package com.cheng.design.demo.template.impl;

import com.cheng.design.demo.template.SendMailTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 这个需要自己写
 */
public class QQMailSend extends SendQQMailTemplate{

    public QQMailSend(String account) {
        super(account);
    }

    @Override
    public Map<String, Object> reloadMapInExcel(Object excel) {
        System.out.println("=========从excle中读取出想要的字段值=======strt=====");
        HashMap<String, Object> stringStringHashMap = new HashMap<>();

        if (!(excel instanceof String)) {
            throw new RuntimeException("excel类型不对");
        }

        String temp = (String) excel;

        String[] split = temp.split(";");

        for (String s : split) {
            stringStringHashMap.put(s, s);
        }

        map = stringStringHashMap;
        System.out.println("=========从excle中读取出想要的字段值========end====");
        return stringStringHashMap;
    }

    @Override
    public Object reloadTemplate(Object template) {
        System.out.println("=========加载模板=========start===");
        if (!(template instanceof String)) {
            throw new RuntimeException("模板类型不对");
        }

        String temp = (String) template;

        this.template = temp;

        System.out.println("=========加载模板=========end===");
        return template;
    }

    @Override
    public Object replaceSign(List<String> placeholders, Object template) {
        System.out.println("===========替换模板中的占位======strt====");

        if (!(template instanceof String)) {
            throw new RuntimeException("模板类型不对");
        }
        String temp = (String) template;

        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(temp);

        for (String s : placeholders) {
            stringBuffer.append(s);
        }

        String result = stringBuffer.toString();

        System.out.println("===========替换模板中的占位======end====");
        return result;
    }


    public static void main(String[] args) {
        String receive = "刘家成;吴卓林;郭文杰";
        String sendAccount = "1092822550@qq.com";
        String sendTemplate = "这是发送的模板，替换成了：";

        SendMailTemplate qqMailSend = new QQMailSend(sendAccount);
        qqMailSend.sendMail(receive, sendTemplate);
    }
}
